import json
import base64

input_json_path = "label.json"
new_image_path = "map_SAR.png"
output_json_path = "label_SAR.json"

with open(input_json_path, "r", encoding="utf-8") as file:
    annotation_data = json.load(file)

annotation_data["imagePath"] = new_image_path

with open(new_image_path, "rb") as image_file:
    encoded_image = base64.b64encode(image_file.read()).decode("utf-8")
    annotation_data["imageData"] = encoded_image

with open(output_json_path, "w", encoding="utf-8") as file:
    json.dump(annotation_data, file, ensure_ascii=False, indent=4)
